package com.iotstudio.embeddedcloudplatform.util;

import net.coobird.thumbnailator.Thumbnails;

import java.io.File;
import java.io.IOException;

/**
 * @author BeFondOfTaro
 * Created at 17:44 2018/1/19
 */
public class ImageUtil {

    /**
     * 创建缩略图，宽度为300px
     * @param originImage 原始图片
     * @throws IOException
     */
    public static void createShortCutImage(File originImage) throws IOException{
        createShortCutImage(originImage,300);
    }

    /**
     * 创建缩略图
     * @param originImage 原始图片
     * @param width 生成图片宽度
     * @throws IOException
     */
    public static void createShortCutImage(File originImage, int width) throws IOException {
        String originFileName = originImage.getName();
        String destFileName = originFileName.replace(".","_min.");
        String destFilePath = originImage.getParentFile().getAbsolutePath()+File.separator+destFileName;
        Thumbnails.of(originImage)
                .width(width)
                .toFile(destFilePath);
    }
}
